#include "mainscene.h"
#include "ui_mainscene.h"
#include "mypushbutton.h"
#include "chooselevelscene.h"
#include <QPainter>
#include <QTimer>
#include <QSound>
mainscene::mainscene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::mainscene)
{
    ui->setupUi(this);
    this->setFixedSize(640,1176);
    this->setWindowTitle("翻金币主场景");
    this->setWindowIcon(QIcon("://res/Coin0001.png"));
    connect(ui->actionQuit,&QAction::triggered,[=](){
       this->close();
    });

    QSound * startSound = new QSound(":/res/TapButtonSound.wav",this);
    QSound * backSound = new QSound(":/res/BackButtonSound.wav",this);

    MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png","",2,2);    
    startBtn->setParent(this);
    startBtn->move(this->width()/2-startBtn->width()/2,this->height()*0.7);

    choosescene = new ChooselevelScene();

    connect(choosescene,&ChooselevelScene::backMainscene,[=](){        
        this->setGeometry(choosescene->geometry());
        backSound->play();
        choosescene->hide();
        this->show();
    });

    connect(startBtn,&QPushButton::clicked,[=](){
        startSound->play();
        startBtn->zoom1();
        startBtn->zoom2();
        QTimer::singleShot(500,this,[=](){
            choosescene->setGeometry(this->geometry());
            this->hide();
            choosescene->show();
        });
    });
}

void mainscene::paintEvent(QPaintEvent *){
    QPainter painter(this);
    QPixmap pixmap;
    pixmap.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pixmap);
    pixmap.load(":/res/Title.png");
    pixmap = pixmap.scaled(pixmap.width(),pixmap.height());
    painter.drawPixmap(10,100,pixmap);
}

mainscene::~mainscene()
{
    delete ui;
}

